package Service;

import DAO.BookDAO;
import DAO.CommentDAO;
import DATA.Book;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "addComment", value = "/addComment")
public class addComment extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int bid= Integer.parseInt(request.getParameter("bid"));
        int uid= (int) request.getSession().getAttribute("uid");//uid就不用前端传过来了，每个用户都是特定的，直接session获取就好
        String content=request.getParameter("content");
        int which= Integer.parseInt(request.getParameter("which"));
        try {
            request.setAttribute("bid",bid);
            System.out.println(CommentDAO.insertCom(bid,uid,content,which));
            request.getRequestDispatcher("getBook2").forward(request,response);
        } catch (SQLException e) {
            throw new RuntimeException("插入失败");
        }
    }
}
